/*
 * @(#)LLMSimilarity.java	1.0 01/01/05
 *
 * Copyright 2007 Fabio Gasparetti. All rights reserved.
 */
package org.tabularium.text.nlp;

import java.io.IOException;

import org.tabularium.text.TermWeightVector;
import org.tabularium.text.TextSimilarity;

/**
 * Draws text similarities according to the cosine measure.
 * 
 * @author  Fabio Gasparetti
 * @version 1.0, 01/01/05
 */
public class LlmSimilarity implements TextSimilarity {

	protected LlmComparator llm = null;
	
	
	public LlmSimilarity() throws IOException {
		llm = new LlmComparator();
	}
	
	/**
	 * WNSim or NESim
	 * default is WNSim;
	 */
	public void setMetricName(String s) {
		llm.setMetricName(s);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.tabularium.text.TextSimilarity#similarity(java.lang.String,
	 *      java.lang.String)
	 */
	public double similarity(String text1, String text2) {
		double result = 0;
//		String config = "llmDefaultConfig.txt";	
		
		try 
		{
//			llm = new LlmComparator( config );	Originale con file di configurazione
			

			result = llm.compareStrings( text1, text2 );
			
//			System.out.println( "compared '" + text1 + "' with '" + text2 + "': ");
//			System.out.println( "LLM score is: " + result );
		}
		catch ( Exception e ) 
		{
			e.printStackTrace();
		}
		return result;
	}


	@Override
	public double similarity(TermWeightVector v1, TermWeightVector v2) {
		return similarity(v1.toPlainString(false), v2.toPlainString(false));
	}
	
	

	
	public static void main(String[] args) 
	{	    

		String source = "Type (or paste) the lol lol Text write here...";
		String target = "Type (or paste) the Hypothesis written Text here...";
		
		LlmComparator llm = null;
		
		try 
		{
			llm = new LlmComparator();

			double result = llm.compareStrings( source, target );
			
			System.out.println( "compared '" + source + "' with '" + target + "': ");
			System.out.println( "LLM score is: " + result );
		}
		catch ( Exception e ) 
		{
			e.printStackTrace();
		}
		
	}
}
